class Solution3 {

    public static void main(String[] args) {
        System.out.println(convert("PAYPALISHIRING", 3));

    }
    public static String convert(String s, int numRows) {
          if(numRows ==1) return s ; 
          int d = 2*numRows-2 ;
          char[] arr = s.toCharArray();
           int len =arr.length ;
           StringBuilder strb = new StringBuilder() ;
           for(int i = 0 ; i < numRows ; i ++){
               int j=i ;
               if(i==0 || i==numRows-1){
                while(j < len){
                    strb.append(arr[j]);
                     j += d ;
                }
               }else{
                while(j < len){
                    strb.append(arr[j]);
                    strb.append(arr[d-i]);
                    j += d ;
                }
               }
           }
         return strb.toString() ;
    }
}